package org.osflash.signals;

import asunit.asserts.*;
import asunit.framework.IAsync;

class SignalDispatchNoArgsTest {

	@:meta(Inject())
	public var async : IAsync;
	public var signal : ISignal;
	@:meta(Before())
	public function setUp() : Void {
		signal = new Signal();
	}

	@:meta(After())
	public function tearDown() : Void {
		signal.removeAll();
		signal = null;
	}

	//////
	@:meta(Test())
	public function dispatch_no_args_should_call_listener_with_no_args() : Void {
		signal.add(async.add(onCompleted, 10));
		signal.dispatch();
	}

	function onCompleted() : Void {
		assertEquals(0, arguments.length);
	}

	//////
	@:meta(Test())
	public function addOnce_in_handler_and_dispatch_should_call_new_listener() : Void {
		signal.addOnce(async.add(addOnceInHandler, 10));
		signal.dispatch();
	}

	function addOnceInHandler() : Void {
		signal.addOnce(async.add(secondAddOnceListener, 10));
		signal.dispatch();
	}

	function secondAddOnceListener() : Void {
	}

}

